package recursivecode;

import java.util.HashSet;
import java.util.Set;

/**
 * 功能描述:子字符串 : 连续的字符
 * 2024/07/12
 *
 * @author ZhangYi
 */
public class SubstringString {

	public static void main(String[] args) {
		String str = "abc";
		Set<String> allSubString = getAllSubString(str);
		System.out.println(1);
	}

	/**
	 * 获取所有子字符串
	 *
	 * @param str str
	 * @return {@code Set<String> }
	 * @author ZhangYi
	 */
	private static Set<String> getAllSubString(String str) {
		if (str == null || str.length() == 0){
			return new HashSet<>();
		}
		Set<String> result = new HashSet<>();
		processAllSubString(str, str,0,result);
		return result;
	}

	/**
	 * 处理所有子字符串
	 *
	 * @param str    str 源字符串,现场的传递,
	 * @param subStr 子str , 子串的结果
	 * @param index  索引,
	 * @param result 结果
	 * @author ZhangYi
	 */
	private static void processAllSubString(String str, String subStr, int index, Set<String> result) {

		for (int i = index; i < str.length(); i++) {
			for (int j = i+1; j <= str.length(); j++) {
				processAllSubString(str,str.substring(i,j), j, result);
			}
		}
		if (index <= str.length()){
			result.add(subStr);
		}
	}
}
